package com.ktgj.flight.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.flight.domain.FlightOrderAttachment;
import com.ktgj.flight.service.IFlightOrderAttachmentService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 订单附件Controller
 * 
 * @author ruoyi
 * @date 2021-10-26
 */
@ControllerAdvice
@RestController
@RequestMapping("/attachment")
public class FlightOrderAttachmentController extends BaseController
{
    @Autowired
    private IFlightOrderAttachmentService flightOrderAttachmentService;

    /**
     * 查询订单附件列表
     */
    @PreAuthorize(hasPermi = "flight:attachment:list")
    @GetMapping("/list")
    public TableDataInfo list(FlightOrderAttachment flightOrderAttachment)
    {
        startPage();
        List<FlightOrderAttachment> list = flightOrderAttachmentService.selectFlightOrderAttachmentList(flightOrderAttachment);
        return getDataTable(list);
    }

    /**
     * 导出订单附件列表
     */
    @PreAuthorize(hasPermi = "flight:attachment:export")
    @Log(title = "订单附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlightOrderAttachment flightOrderAttachment) throws IOException
    {
        List<FlightOrderAttachment> list = flightOrderAttachmentService.selectFlightOrderAttachmentList(flightOrderAttachment);
        ExcelUtil<FlightOrderAttachment> util = new ExcelUtil<FlightOrderAttachment>(FlightOrderAttachment.class);
        util.exportExcel(response, list, "订单附件数据");
    }

    /**
     * 获取订单附件详细信息
     */
    @PreAuthorize(hasPermi = "flight:attachment:query")
    @GetMapping(value = "/{attachmentId}")
    public AjaxResult getInfo(@PathVariable("attachmentId") Long attachmentId)
    {
        return AjaxResult.success(flightOrderAttachmentService.selectFlightOrderAttachmentById(attachmentId));
    }

    /**
     * 新增订单附件
     */
    @PreAuthorize(hasPermi = "flight:attachment:add")
    @Log(title = "订单附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlightOrderAttachment flightOrderAttachment)
    {
        return toAjax(flightOrderAttachmentService.insertFlightOrderAttachment(flightOrderAttachment));
    }

    /**
     * 修改订单附件
     */
    @PreAuthorize(hasPermi = "flight:attachment:edit")
    @Log(title = "订单附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlightOrderAttachment flightOrderAttachment)
    {
        return toAjax(flightOrderAttachmentService.updateFlightOrderAttachment(flightOrderAttachment));
    }

    /**
     * 删除订单附件
     */
    @PreAuthorize(hasPermi = "flight:attachment:remove")
    @Log(title = "订单附件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{attachmentIds}")
    public AjaxResult remove(@PathVariable Long[] attachmentIds)
    {
        return toAjax(flightOrderAttachmentService.deleteFlightOrderAttachmentByIds(attachmentIds));
    }
}
